﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XnaCanvas;
using matrix = Microsoft.Xna.Framework.Matrix;

namespace Test.Scenes {
    /// <summary>
    /// 画九宫格平面
    /// </summary>
    public partial class XnaPanel : UserControl {
        public XnaPanel() {
            InitializeComponent();
            this.Loaded += XnaPanel_Loaded;
            this.xcanvas.Trigger.FrameRefresh += Trigger_FrameRefresh;
        }

        void Trigger_FrameRefresh(XTrigger sender) {
            //在这里 写 xo的 旋转
            xo.World *= matrix.CreateRotationX(.01f);
            xo.World *= matrix.CreateRotationY(.01f);
            xo.World *= matrix.CreateRotationZ(.01f);
            //xs.viewer *= matrix.CreateRotationY(.01f);
            //xs.viewer *= matrix.CreateRotationX(.01f);

            //Quaternion q; Vector3 translate, s;
            //xs.viewer.Decompose(out s, out q, out translate);
            //var x = Quaternion.CreateFromYawPitchRoll(.05f, .05f, .05f);
            //var x2 = q * x;
            //xs.viewer = matrix.CreateScale(s) * matrix.CreateFromQuaternion(x2) * matrix.CreateTranslation(translate.X, translate.Y, translate.Z);
        }
        XObj3 xo;
        XSence xs;
        void XnaPanel_Loaded(object sender, RoutedEventArgs e) {
            xs = this.xcanvas.Children[xcanvas.Trigger.Csn];
            //xs.InitialCamera(50);
            xo = new XObj3();
            //xcanvas.Trigger.Rs.FillMode = Microsoft.Xna.Framework.Graphics.FillMode.WireFrame;
            //xcanvas.Trigger.Rs.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.None;
            xs.Add("aaa", xo);
            xo.SetColor(100, 100, 225, 200);
            //xo.effect.Alpha = 1.0f;
            //xo.effect.AmbientLightColor = new Vector3(100, 100, 100);
            //xo.LoadGridPrimitive(r: .25f, func: (x, y) => (float)(Math.Pow(1 + x, 2) + Math.Pow(1 + y, 2)));
            xo.LoadGridPrimitive(r: .25f);
            //xo.LoadTorusPrimitive();
            //xs.viewer *= matrix.CreateTranslation(-5, -5, 0);
            this.xcanvas.Begin();
        }
    }
}
